(function () {
    var core = ecui,
        util = ecui.util,
        dom = ecui.dom;
    ecui.util.extend(
        NS.ui,
        {
            SponsorCommentSave: core.inherits(
                mao.ui.CommentSave,
                {
                    onsubmit: function () {
                        if (this._oRequest) {
                            return;
                        }
                        this._oRequest = true;
                        var form = this.getInput().form;
                        if (this.action === '7') {
                            // 评论
                            ecui.esr.request(
                                'data@JSON /erp-management/customer/sponsor/remark?id=' + form.id.value + '&remark=' + form.remark.value,
                                function () {
                                    this._oRequest = false;
                                    var data = ecui.esr.getData('data');
                                    if (data instanceof Object) {
                                        ecui.tip('warn', '评论成功');
                                        ecui.esr.getRoute('detail.sponsor').CACHE = false;
                                        ecui.esr.callRoute(util.stringFormat('detail.sponsor~orderSn={0}~moduleType={1}~initiate={2}', ecui.esr.getData('orderSn'), ecui.esr.getData('moduleType'), ecui.esr.getData('initiate')));
                                    }
                                }.bind(this),
                                function () {
                                    this._oRequest = false;
                                }.bind(this)
                            );
                        } else if (this.action === '6') {
                            // 删除
                            ecui.esr.request(
                                'data@FORM /erp-management/customer/sponsor/delete/' + form.name.id,
                                function () {
                                    this._oRequest = false;
                                    var data = ecui.esr.getData('data');
                                    if (data instanceof Object) {
                                        ecui.tip('warn', '删除成功');
                                        ecui.esr.getRoute('/approval/initiate.initiate').CACHE = false;
                                        history.go(-1);
                                    }
                                }.bind(this),
                                function () {
                                    this._oRequest = false;
                                }.bind(this)
                            );
                        } else if (this.action === '5') {
                            // 编辑
                            this._oRequest = false;
                        } else {
                            // 0-撤销 1-提交 2-驳回 3-通过 4-中止
                            var tip = ['撤销', '提交', '驳回', '通过', '中止'];
                            ecui.esr.request(
                                'data@FORM /erp-management/customer/sponsor/audit/action?' + form.name,
                                function () {
                                    this._oRequest = false;
                                    var data = ecui.esr.getData('data');
                                    if (data instanceof Object) {
                                        ecui.tip('warn', tip[+this.action] + '成功');
                                        if (ecui.esr.getData('initiate') === 'true') {
                                            ecui.esr.getRoute('/approval/initiate.initiate').CACHE = false;
                                        } else {
                                            ecui.esr.getRoute('/approval/approve').CACHE = false;
                                        }
                                        history.go(-1);
                                    }
                                }.bind(this),
                                function () {
                                    this._oRequest = false;
                                }.bind(this)
                            );

                        }
                    }
                }
            )
        }
    );
    ecui.esr.addRoute('sponsor', {
        model: ['detail@GET /erp-management/customer/sponsor/${orderSn}?msgId=${msgId}'],
        weight: 4,
        main: 'approval_detail-sponsor',
        view: 'detail.sponsor',
        frame: true,
        CACHE: false,
        onbeforerequest: function (context) {
        },
        onbeforerender: function (context) {
            ecui.esr.setData('sponsorTitle', context.detail.creatorName + '的主办方申请');
            mao.util.setTitle(context.detail.creatorName + '的主办方申请');
        }
    });
}());